package com.console.operations.usermgr;

import com.common.test.OperationBase;
import com.common.test.UITestBase;
import com.common.util.DBUtil;
import com.console.pages.usermgr.AddUserPage;

public class AddUser extends OperationBase {

	public AddUser(UITestBase tb){
		super(tb);
	}
	
	public boolean isquerylogindata = false;
	
	public void addUser(String cellphone, String nickname, String name, String idno, String password, String sourceChannel) throws Exception{
		//如果手机号码在系统里已注册
		if(DBUtil.isQueryData("select * from fiz_user where vc_cellphone = ?", new Object[]{cellphone})){
			if(DBUtil.isQueryData("select * from fiz_user where vc_cellphone = ?", new Object[]{"13812345678"})){
				DBUtil.update("delete from fiz_user where vc_cellphone = ?", new Object[]{"13812345678"});
			}
			DBUtil.update("update fiz_user set vc_cellphone = ? where vc_cellphone = ?", new Object[]{"13812345678", cellphone});
		}
		//如果昵称在系统里已注册
		if(DBUtil.isQueryData("select * from fiz_user where vc_account = ?", new Object[]{nickname})){
			if(DBUtil.isQueryData("select * from fiz_user where vc_account = ?", new Object[]{"nickname"})){
				DBUtil.update("delete from fiz_user where vc_account = ?", new Object[]{"nickname"});
			}
			DBUtil.update("update fiz_user set vc_account = ? where vc_account = ?", new Object[]{"nickname", nickname});
		}
		//如果身份证号在系统里已注册
		if(DBUtil.isQueryData("select * from fiz_user_prop where vc_code = ? and vc_value = ?", new Object[]{"code-identity-number", idno})){
			if(DBUtil.isQueryData("select * from fiz_user_prop where vc_code = ? and vc_value = ?", new Object[]{"code-identity-number", "355190012208888"})){
				DBUtil.update("delete from fiz_user_prop where vc_code = ? and vc_value = ?", new Object[]{"code-identity-number", "355190012208888"});
			}
			DBUtil.update("update fiz_user_prop set vc_value = ? where vc_code = ? and vc_value = ?", new Object[]{"355190012208888", "code-identity-number", idno});
		}
		
		switchToDefaultContent();
		AddUserPage ap = new AddUserPage(tb);
		waitForElementExist(ap.cellphoneEditInput);
		//输入手机号
		ap.cellphoneEditInput.type(cellphone);
		pause(600);
		//输入昵称
		ap.nicknameInput.type(nickname);
		pause(600);
		//输入姓名
		ap.nameInput.type(name);
		pause(600);
		//输入身份证号
		ap.numberEditInput.type(idno);
		pause(600);
		//输入密码
		ap.passwordInput.type(password);
		pause(600);
		ap.confirmpwdInput.type(password);
		pause(600);
		//选择平台
		ap.sourceChannelSelect.selectOptionByText(sourceChannel);
		ap.saveoperation.click();
		waitForPageContainsStr("新增用户成功");
		pause(1000);
		isquerylogindata = DBUtil.isQueryData("select * from fiz_user where vc_cellphone = ?", new Object[]{cellphone});
		if(!isquerylogindata){
			return;
		}
	}
}
